//
//  UIImage+TYScaleImage.m
//  TYToolKit
//
//  Created by dev_tianyu on 16/8/25.
//  Copyright © 2016年 dev_tianyu. All rights reserved.
//

#import "UIImage+TYScaleImage.h"

@implementation UIImage (TYScaleImage)

/**
 *  等比例缩放到指定宽度
 */
-(UIImage *) scaleImageWithSize:(CGFloat)newWidth{
    
    CGSize originalSize = self.size;
    
    CGFloat scale = newWidth / originalSize.width;
    
    CGFloat height = originalSize.height * scale;
    
    CGSize newSize = CGSizeMake(newWidth, height);
    
    UIGraphicsBeginImageContext(newSize);
    
    [self drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    
    UIImage *scaleImage = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return scaleImage;
}

@end
